package com.fortune.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fortune.constants.Constants;
import com.fortune.dao.MChannelDiscountDao;
import com.fortune.dto.in.mChannelDiscount.MChannelDiscountAddDto;
import com.fortune.dto.in.mChannelDiscount.MChannelDiscountDeleteDto;
import com.fortune.dto.in.mChannelDiscount.MChannelDiscountEditDto;
import com.fortune.dto.in.mChannelDiscount.MChannelDiscountListDto;
import com.fortune.entity.MUserInfo;
import com.fortune.service.MChannelDiscountServer;
import com.fortune.vo.mChannelDiscount.MChannelDiscount;
@Service
public class MChannelDiscountServerImpl implements MChannelDiscountServer{
	
	@Autowired
	private MChannelDiscountDao mChannelDiscountDao;
	@Override
	public List<MChannelDiscount> list(MUserInfo mUserInfo,MChannelDiscountListDto listDto) {
		List<MChannelDiscount> list = mChannelDiscountDao.list(mUserInfo,listDto);
		return list;
	}
	@Override
	public int count(MUserInfo mUserInfo,MChannelDiscountListDto listDto) {
		int count  = mChannelDiscountDao.count(mUserInfo,listDto);
		return count;
	}
	@Override
	public int add(MUserInfo mUserInfo,MChannelDiscountAddDto addDto) {
		Integer check = mChannelDiscountDao.checkAdd(mUserInfo,addDto);
		if (check == null) {
			int result = mChannelDiscountDao.add(mUserInfo,addDto);
			return result;
		}
		return 2;
	}
	@Override
	public int edit(MUserInfo mUserInfo,MChannelDiscountEditDto editDto) {
		Integer check = mChannelDiscountDao.checkEdit(mUserInfo,editDto);
		if (check != null) {
			int result = mChannelDiscountDao.update(mUserInfo,editDto);
			return result;
		}
		return 2;
	}
	@Override
	public int delete(MUserInfo mUserInfo,MChannelDiscountDeleteDto deleteDto) {
		String check = mChannelDiscountDao.checkDelete(mUserInfo,deleteDto);
		if (check==null) {
			return 2;
		}else if (check.equals(Constants.DELETE)) {
			return 3;
		}else {
			int result = mChannelDiscountDao.delete(mUserInfo,deleteDto);
			return result;
		}
		
	}

}
